#include "qmainsence.h"
#include "ui_qmainsence.h"
#include "maingame.h"
#include <QPushButton>
#include <QPainter>

Qmainsence::Qmainsence(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::Qmainsence)
{
    ui->setupUi(this);

    //创建单机游戏
    game1=new maingame;
    connect(game1,&maingame::game_back,[=](){
        game1->hide();
        game1->games->game_init();
        this->show();

    });
    connect(game1,&maingame::game_back_continue,[=](){
        game1->hide();
        this->show();

    });



    //创建网络游戏
    networkgame1=new qnetworkgame;
    connect(networkgame1,&qnetworkgame::back_main,[=](){
        networkgame1->hide();
        this->show();

    });

    connect(networkgame1->game2,&netgame::game_back,[=](){
        networkgame1->game2->close();
        this->show();
    });
    connect(networkgame1,&qnetworkgame::exit_game,[=](){
        networkgame1->game2->close();
        this->show();
    });

    //创建AI游戏
    ai_game=new AIgame;
    connect(ai_game,&AIgame::game_back,[=](){
        ai_game->close();
        this->ai_game->games->game_init();
        this->show();
    });


    //页面设置
    setFixedSize(1000,800);
    setWindowIcon(QIcon(":/res/R-C.jpg"));
    setWindowTitle("五子棋游戏");
    //开始按钮
    QPushButton* startbtn=new QPushButton("单机游戏",this);
    startbtn->setFixedSize(200,60);
    startbtn->setFont(QFont("SimHei",15,QFont::Bold));
    startbtn->move(this->width()*0.5-startbtn->width()*0.5,this->height()*0.75);

    QPushButton* startbtn_net=new QPushButton("网络游戏",this);
    startbtn_net->setFixedSize(200,60);
    startbtn_net->setFont(QFont("SimHei",15,QFont::Bold));
    startbtn_net->move(this->width()*0.5-startbtn->width()*0.5,this->height()*0.65);


    QPushButton* startbtn_AI=new QPushButton("人机对战",this);
    startbtn_AI->setFixedSize(200,60);
    startbtn_AI->setFont(QFont("SimHei",15,QFont::Bold));
    startbtn_AI->move(this->width()*0.5-startbtn->width()*0.5,this->height()*0.55);
    //开始游戏
    connect(startbtn,QPushButton::clicked,[=](){
        this->hide();
        game1->show();
    });

    connect(startbtn_net,QPushButton::clicked,[=](){
        this->hide();
        networkgame1->show();
    });

    connect(startbtn_AI,QPushButton::clicked,[=](){
        this->hide();
        ai_game->show();
    });

}
void Qmainsence::paintEvent(QPaintEvent *)
{
    QPainter painter(this);
    QPixmap pix;
    pix.load(":/new/prefix1/res/9801.png");
    painter.drawPixmap(0,0,this->width(),this->height(),pix);
}
Qmainsence::~Qmainsence()
{
    delete ui;
}
